package susi;

import java.awt.Dimension;
import java.io.File;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class DemoMain extends JFrame {

	public static void main(String[] args) {
		new DemoMain();
	}
	
	
	public DemoMain() {
		Document document = null;
		try {
			DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = dbFactory.newDocumentBuilder();
			document = builder.parse(new File("src/inBucket.xml"));
			document.normalize();
		}
		catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
		
		Document opDoc = null;
		try {
			DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = dbFactory.newDocumentBuilder();
			opDoc = builder.parse(new File("src/outBucket.xml"));
			opDoc.normalize();
		}
		catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
		
		XMLTreePanel inputSchemaTree = new XMLTreePanel();
		inputSchemaTree.setDocument(document);
		
		JTextArea inputTextArea = new JTextArea(30, 20);
		JTextArea codeTextArea = new JTextArea(30, 20);
		JTextArea outputTextArea = new JTextArea(30, 20);
		
		XMLTreePanel outputSchemaTree = new XMLTreePanel();
		outputSchemaTree.setDocument(opDoc);
		
		JPanel docContainer = new JPanel();
		docContainer.setLayout(new BoxLayout(docContainer, BoxLayout.X_AXIS));

		//panel1.set[Preferred/Maximum/Minimum]Size()
		docContainer.add(inputTextArea);
		docContainer.add(inputSchemaTree);
		docContainer.add(codeTextArea);
		docContainer.add(outputSchemaTree);
		docContainer.add(outputTextArea);
		
		JPanel verticalContainer = new JPanel();
		verticalContainer.setLayout(new BoxLayout(verticalContainer, BoxLayout.Y_AXIS));
		JPanel topPanel = new JPanel();
		topPanel.setPreferredSize(new Dimension(200, 30));
		JPanel buttomPanel = new JPanel();
		buttomPanel.setPreferredSize(new Dimension(200, 30));
		verticalContainer.add(topPanel);
		verticalContainer.add(docContainer);
		verticalContainer.add(buttomPanel);
		
		getContentPane().add(verticalContainer);
		
		pack();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("XML Tree Demo");
		setLocationRelativeTo(null);
		setVisible(true);
	}

}
